let core = require("@babel/core");
const { getOptions } = require("loader-utils");

function loader(source,inputSourceMap,inputast) {
  //let options = getOptions(this) || {};
  let options =  {};
  options = {
      presets:['@babel/preset-env'],
      inputSourceMap,
      sourceMaps:true,//生成sourcemap
      filename:this.resourcePath,
      ...options
  }
  let {code,map,ast} = core.transform(source,options)
  //return code //如果翻译的是一个值
  //如果返回的是多个值
  return this.callback(null,code,map,ast)
}

module.exports = loader;

// devtool
// source-map 包含loader的sourcemap
//index.js 可能会经过好几个loader的处理，每个loader都有坑